<?php require_once dirname(__FILE__) . "/shared/config/config.php"; ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
        <title>conference News - Tesdo</title>
        <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?>
        <meta name="viewport" content="width=device-width" />
        <?php
        require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_conferences.php";
        require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_news.php";
        require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . "lib_pager.php";

        $news_access = new dao_news();
        $conferences_access = new dao_conferences();
        $lib_pager = new lib_pager();

//        $conferences = $conferences_access->get_all();
//        if (isset($conferences) && sizeof($conferences) > 0) {
//            $conference_id = $conferences[0]["conference_id"];
//            $page_title = $conferences[0]["conference_name"];
//            $newses = $news_access->get_all_by_conference_id($conference_id);
//        } else {
//            $page_title = 'Not conference found';
//        }
        
        
        $page_title = "News List";
        //$newses_archive = $news_access->get_all_archive_by_paper_category_id($conference_id);
        $newses = $news_access->get_all();
        
        if (!empty($_GET['arc_conferences_id'])) {
//            $conference_id = $_GET['arc_conferences_id'];
//            if (!empty($_GET['month'])) {
//                $month = $_GET['month'];
//            }
//            if (!empty($_GET['year'])) {
//                $year = $_GET['year'];
//            }
//            $page_title = $conferences_access->get_by_id($conference_id);
//            $newses_archive = $news_access->get_all_archive_by_paper_category_id($conference_id);
//            $newses = $news_access->get_all_by_paper_category_id_and_date($conference_id, $month, $year);
        } else if (!empty($_GET['news_id'])) {
            $news_id = $_GET['news_id'];
            $news = $news_access->get_by_id($news_id);
//            $conference_id = $news['conference_id'];
//            $conference = $conferences_access->get_by_id($conference_id);
            $page_title = "News Detail";
            //$newses_archive = $news_access->get_all_archive_by_paper_category_id($conference_id);
        }

        
        ?>
    </head>
    <body>
        <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'header.php'; ?>

        <!-- Body -->
        <div id="body">
            <section class="content-wrapper main-content clear-fix">
                <div class="DetailPage">
                    <hgroup class="title">
                        <h1>
                            <span id="MainContent_lblTitle">
                                <?php echo $page_title; ?>
                            </span></h1>
                        <h2></h2>
                    </hgroup>
<!--                    <div class="LeftArea">
                        <div id="left_menu">
                            <div>
                                <table id="MainContent_dlcatList" cellspacing="0" style="border-collapse:collapse;">
                                    <tbody>
                                        <?php
                                        foreach ($conferences as $i => $item) {
                                            ?>
                                            <tr>
                                                <td>
                                                    <ul>
                                                        <li><a href="news_list.php?conference_id=<?php echo $item['conference_id']; ?>"><?php echo $item['conference_name']; ?></a></li>
                                                    </ul>
                                                </td>
                                            </tr>
                                            <?php
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>-->
                    <article class="CenterArea">
                        <?php 
                        if (!empty($_GET['arc_conferences_id']) || !empty($_GET['conference_id']) || empty($_GET) || !empty($_GET['p'])) {
                            
                            if (empty($newses) || sizeof($newses) <= 0) {
                                echo "Not news found.";
                            } else {
                                $current_page = 1;
                                $page_size = 10;
                                if (!empty($_GET['p'])) {
                                    $current_page = $_GET['p'];
                                }

                                $list_total = $newses;
                                $total_page = $lib_pager->get_total_page($list_total, $page_size);
                                $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total);

                                $count = 0;
                                foreach ($current_page_list as $i => $item) {
                                    ?>
                                    <table id="MainContent_dlPapers" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
                                        <tbody><tr>
                                                <td>
                                                    <div class="adsSortDetail">
                                                        <div>
                                                            <b> <a href="news_list.php?news_id=<?php echo $item["News_Id"]; ?>" style="color:blue; font-size:14px;"><?php echo $item["News_Title"]; ?></a></b><br>
                                                            <b>Added on:</b> <?php echo $item["Addedon"]; ?> <br>
                                                            <hr>
                                                            <b><a href="news_list.php?news_id=<?php echo $item["News_Id"]; ?>" style="color:blue; font-size:14px;">DETAIL</a></b>
                                                            <hr>
                                                            
                                                        </div>
                                                    </div></td>
                                            </tr>
                                        </tbody></table>
                                    <?php
                                }
                                
//                                if (!empty($_GET['conference_id'])) {
//                                    $params = "&conference_id=" . $conference_id;
//                                } 
//                                else if (!empty($_GET['arc_conferences_id'])) {
//                                    $params = "&arc_conferences_id=" . $conference_id . "&month=" . $month . "&year=" . $year;
//                                }
                                ?>
                                <table>
                                    <tbody>
                                        <tr>
                                            <?php for ($a = 1; $a <= $total_page; $a++) { ?>
                                                <td>
                                                    <span>
                                                        <a href="news_list.php?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a>
                                                    </span>
                                                </td>
                                            <?php } ?>
                                        </tr>
                                    </tbody>
                                </table>
                                
                                <?php
                            }
                        }
                        ?>

                        <?php
                        if (!empty($_GET['news_id'])) {
                            $item = $news;
                            ?>
                            <div id="MainContent_AbstractDeail" class="AbstractDeail">
                                <h4><span id="MainContent_lblAbsTitle"><?php echo $item["News_Title"]; ?></span></h4>
                                <hr>
                                <h5>Description:</h5>
                                <p> <span id="MainContent_lblAuthor"><?php echo $item["News_Description"]; ?> </span></p>
                                <h5>Added on:</h5>
                                <p>  <span id="MainContent_lblCitation"><?php echo $item["Addedon"]; ?></span></p>
                                <hr>
                            </div>
                            <?php
                        }
                        ?>
                    </article>
                <aside>
                    <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'navbar.php'; ?>
                </aside>
                </div>
            </section>
        </div>
        <!-- End Body -->

        <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?>
    </body>
</html>